/**
 * 静态类型信息管理
 * @author qiuxj
 */
var staticType = {
    init: function(dwr){
        // 增加按钮
        var addBtn = new CQCIS.Button({
            text: '添加 (<u>A</u>)',
            iconCls: 'btn_insert',
            handler: function(){
        		typeWin.show();
            }
        });
        
        // 修改按钮
        var editBtn = new CQCIS.Button({
            text: '修改 (<u>E</u>)',
            iconCls: 'btn_modify',
            handler: function(){
                if (Agrid.getSelectedRow()) {
                	typeWin.load(Agrid.getSelectedRow()['staticTypeId']);
                } else {
                    CQCIS.msg("请选择要修改的静态值！");
                }
            }
        });
        
        // 添加员工信息表单字段
        var typeFormMeta = [{
            id: 'staticTypeId',
            desc: '静态类型ID',
            field: 'staticTypeId',
            type: 'int'
        }, {
            field: 'staticTypeName',
            desc: '静态值名称',
            obj: {
                allowBlank: false
            }
        }, {
            field: 'chooseCond1',
            desc: '控制值一',
            obj: {
                value: 'NULL'
            }
        }, {
            field: 'chooseCond2',
            desc: '控制值二',
            obj: {
                value: 'NULL'
            }
        }, {
            field: 'chooseCond3',
            desc: '控制值三',
            obj: {
                value: 'NULL'
            }
        }];
        
        // 员工列表数据
        var typeListMeta = [{
            id: 'staticTypeId',
            desc: '静态值类型ID',
            field: 'staticTypeId',
            type: 'int',
            hidden: true
        }, {
            field: 'staticTypeName',
            desc: '静态值名称'
        }, {
            field: 'chooseCond1',
            desc: '控制值一'
        }, {
            field: 'chooseCond2',
            desc: '控制值二'
        }, {
            field: 'chooseCond3',
            desc: '控制值三'
        }];
        
        // 定义表单
        var typeForm = new CQCIS.form.DWRForm({
            dwr: {
                load: dwr.getStaticType,
                save: dwr.createStaticType,
                update: dwr.updateStaticType
            },
            metas: typeFormMeta,
            listeners: {
                'saveafter': function(){
                    CQCIS.msg('静态值类型信息保存成功！');
                    Agrid.reload();
                }
            }
        });
        
        // 定义窗口
        var typeWin = new CQCIS.form.WinForm({
            title: '添加静态值类型',
            width: 420,
            height: 280,
            items: typeForm
        });
        
        // 代理商列表
        var Agrid = new CQCIS.grid.PageGrid({
            el: 'staticType',
            title: '静态值类型信息',
            firstColumn: 'radio',
            dwr: {
                call: dwr.pageStaticType
            },
            filter: {},
            sortable: true,
            metas: typeListMeta,
            tbar: ['-', addBtn, '-', editBtn],
            bbar: true,
            initload: true,
            listeners: {
                'rowdblclick': editBtn.handler,
                'rowcontextmenu': function(o, rowIndex, e){
                    e.stopEvent();
                    //定义增加右键菜单
                    var addMenu = new Ext.menu.Item({
                        iconCls: 'menu_insert',
                        id: 'addMenu',
                        text: '增加',
                        handler: addBtn.handler
                    });
                    //定义修改右键菜单
                    var editMenu = new Ext.menu.Item({
                        iconCls: 'menu_modify',
                        text: '修改',
                        handler: editBtn.handler
                    });
                    //定义列表右键菜单
                    var gridMenu = new Ext.menu.Menu({
                        id: 'gridMenu',
                        items: [addMenu, editMenu]
                    });
                    gridMenu.showAt(e.getXY());
                },
                'render': function(o){
                    o.getSelectionModel().on('selectionchange', function(sm){
                        if (sm.getCount() > 0) {
                        	vStaticValue.enable();
                        } else {
                        	vStaticValue.disable();
                        }
                    });
                }
            }
        });
        return Agrid;
    }
};
